package com.sc.nft.entity.dto;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.sc.nft.entity.CollectionGift;
import com.sc.nft.enums.CollectionOriginalTypeEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.compress.utils.Lists;

import java.util.ArrayList;
import java.util.List;
@Data
public class CollectionGiftTransitionDTO {
    @ApiModelProperty("藏品转赠的数据")
    private List<CollectionGift> list;

    public void transition(AddEquityPropsGiftDTO data, Long collectionId,Boolean isGive) {
        if (isGive) {
            if (CollUtil.isEmpty(list)) {
                list = new ArrayList<>();
            }
            if (ObjectUtil.isNotNull(data.getBalanceConsume())) {
                CollectionGift propGift = new CollectionGift();
                propGift.setCollectionId(collectionId);
                propGift.setConsumeType(2);
                propGift.setOriginalType(CollectionOriginalTypeEnum.MATE_UNIVERSE);
                propGift.setQuantityConsume(data.getBalanceConsume().toString());
                list.add(propGift);
            }

            if (ObjectUtil.isNotNull(data.getDebrisConsume())) {
                CollectionGift propGift1 = new CollectionGift();
                propGift1.setCollectionId(collectionId);
                propGift1.setConsumeType(1);
                propGift1.setOriginalType(CollectionOriginalTypeEnum.MATE_UNIVERSE);
                propGift1.setQuantityConsume(data.getDebrisConsume().toString());
                list.add(propGift1);
            }

            if (ObjectUtil.isNotNull(data.getEcologyConsume())) {
                CollectionGift ecologyConsume = new CollectionGift();
                ecologyConsume.setCollectionId(collectionId);
                ecologyConsume.setConsumeType(3);
                ecologyConsume.setOriginalType(CollectionOriginalTypeEnum.MATE_UNIVERSE);
                ecologyConsume.setQuantityConsume(data.getEcologyConsume().toString());
                list.add(ecologyConsume);
            }
        }else {
            if (CollUtil.isEmpty(list)) {
                list = new ArrayList<>();
            }
            CollectionGift propGiftBalanceConsume = new CollectionGift();
            propGiftBalanceConsume.setCollectionId(collectionId);
            propGiftBalanceConsume.setConsumeType(2);
            propGiftBalanceConsume.setOriginalType(CollectionOriginalTypeEnum.MATE_UNIVERSE);
            propGiftBalanceConsume.setQuantityConsume("0");
            list.add(propGiftBalanceConsume);

            CollectionGift propGiftQuantityConsume = new CollectionGift();
            propGiftQuantityConsume.setCollectionId(collectionId);
            propGiftQuantityConsume.setConsumeType(1);
            propGiftQuantityConsume.setQuantityConsume("0");
            propGiftQuantityConsume.setOriginalType(CollectionOriginalTypeEnum.MATE_UNIVERSE);
            list.add(propGiftQuantityConsume);

            CollectionGift propGiftEcologyConsume = new CollectionGift();
            propGiftEcologyConsume.setCollectionId(collectionId);
            propGiftEcologyConsume.setConsumeType(1);
            propGiftEcologyConsume.setQuantityConsume("0");
            propGiftEcologyConsume.setOriginalType(CollectionOriginalTypeEnum.MATE_UNIVERSE);
            list.add(propGiftEcologyConsume);
        }

    }

    public void addCrossChainTransition(AddEquityPropsGiftDTO data, Long collectionId, Boolean isGiveImeta) {
        if (CollUtil.isEmpty(list)) {
            list = new ArrayList<>();
        }

        if (isGiveImeta) {

            if (ObjectUtil.isNotNull(data.getBalanceConsume())) {
                CollectionGift propGift = new CollectionGift();
                propGift.setCollectionId(collectionId);
                propGift.setConsumeType(2);
                propGift.setOriginalType(CollectionOriginalTypeEnum.MATE_WALLET);
                propGift.setQuantityConsume(data.getBalanceConsume().toString());
                list.add(propGift);
            }

            if (ObjectUtil.isNotNull(data.getDebrisConsume())) {
                CollectionGift propGift1 = new CollectionGift();
                propGift1.setCollectionId(collectionId);
                propGift1.setConsumeType(1);
                propGift1.setOriginalType(CollectionOriginalTypeEnum.MATE_WALLET);
                propGift1.setQuantityConsume(data.getDebrisConsume().toString());
                list.add(propGift1);
            }

            if (ObjectUtil.isNotNull(data.getEcologyConsume())) {
                CollectionGift ecologyConsume = new CollectionGift();
                ecologyConsume.setCollectionId(collectionId);
                ecologyConsume.setConsumeType(3);
                ecologyConsume.setOriginalType(CollectionOriginalTypeEnum.MATE_WALLET);
                ecologyConsume.setQuantityConsume(data.getEcologyConsume().toString());
                list.add(ecologyConsume);
            }
        }else {
            CollectionGift propGiftBalanceConsume = new CollectionGift();
            propGiftBalanceConsume.setCollectionId(collectionId);
            propGiftBalanceConsume.setConsumeType(2);
            propGiftBalanceConsume.setQuantityConsume("0");
            propGiftBalanceConsume.setOriginalType(CollectionOriginalTypeEnum.MATE_WALLET);
            list.add(propGiftBalanceConsume);

            CollectionGift propGiftQuantityConsume = new CollectionGift();
            propGiftQuantityConsume.setCollectionId(collectionId);
            propGiftQuantityConsume.setConsumeType(1);
            propGiftQuantityConsume.setQuantityConsume("0");
            propGiftQuantityConsume.setOriginalType(CollectionOriginalTypeEnum.MATE_WALLET);
            list.add(propGiftQuantityConsume);

            CollectionGift propGiftEcologyConsume = new CollectionGift();
            propGiftEcologyConsume.setCollectionId(collectionId);
            propGiftEcologyConsume.setConsumeType(1);
            propGiftEcologyConsume.setQuantityConsume("0");
            propGiftEcologyConsume.setOriginalType(CollectionOriginalTypeEnum.MATE_WALLET);
            list.add(propGiftEcologyConsume);
        }
    }
}
